using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    class MRPImportTypesService
    {
        ISession session;

        public MRPImportTypesService(ISession session)
        {
            this.session = session;
        }
        public MRPImportTypesService()
        {
            this.session = SessionFactory.GetNewSession();
        }

        public void InsertMrpimporttypes(MRPImportTypes mrpimporttypesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpimporttypesX);
            tx.Commit();
        }

        public void UpdateMrpimporttypes(MRPImportTypes mrpimporttypesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpimporttypesX);
            tx.Commit();
        }

        public void DeleteMrpimporttypes(MRPImportTypes mrpimporttypesX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpimporttypesX);
            tx.Commit();
        }

        public IList<MRPImportTypes> GetAllMrpimporttypes(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPImportTypes");
            IList<MRPImportTypes> list = query.List<MRPImportTypes>();
            if (evict)
            {
                foreach (MRPImportTypes s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPImportTypes GetAllMrpimporttypesByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPImportTypes as c where c.Importtypecode= :x");
            query.SetString("x", id);
            MRPImportTypes s = (MRPImportTypes)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPImportTypes> GetMrpimporttypesByQuery(IQuery query, Boolean evict)
        {
            IList<MRPImportTypes> list = query.List<MRPImportTypes>();
            if (evict)
            {
                foreach (MRPImportTypes s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
